package org.chat.hhdchat.Service.Impl;

import org.chat.hhdchat.Service.MessageService;
import org.chat.hhdchat.entity.ChatMessage;
import org.chat.hhdchat.repository.ChatMessageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    ChatMessageRepository chatMessageRepository;

    @Override
    public List<ChatMessage> getMessagesBetweenUsers(String from, String to) {
        List<ChatMessage> historicalChat = chatMessageRepository.findByToUserIdAndFromUserId(to,from);
        System.out.println("用户"+to+"查看"+from+"历史记录"+historicalChat);
        historicalChat.forEach(hc ->{
            System.out.println("用户:" + hc.getToUserId() +"和对方:"+hc.getFromUserId() +"的历史记录:"+hc.getContent());
        });
        return historicalChat;
    }

    @Override
    public void deleteMessage(String messageId) {

    }
}
